package com.huluobo.a2112mvvmdouyindemo.collect;

import androidx.lifecycle.MutableLiveData;

import com.huluobo.mvvm_base.bean.VideoBeanResult;
import com.huluobo.mvvm_base.model.BaseRepo;

import java.util.List;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by LC on 2024/4/10.
 */
public class CollectRepo extends BaseRepo {
    public void getCollectVideos(MutableLiveData<List<VideoBeanResult.VideoBean>> success,
                                 MutableLiveData<String> failed) {
        videoDao.queryVideos()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<List<VideoBeanResult.VideoBean>>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(List<VideoBeanResult.VideoBean> videoBeans) {
                        success.setValue(videoBeans);
                    }

                    @Override
                    public void onError(Throwable e) {
                        failed.setValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
}
